<template>
	<view class="content">
		<!-- <mescroll-uni ref="mescrollRef" @init="mescrollInit" @up="upCallback" :up="upOption"> -->
		<view class="section-0">
			<view class="section-body">
				<view class="form">
					<view class="form-item">
						<view class="label">单位名称</view>
						<view class="shape"></view>
						<view class="input">
							<u--input placeholderClass="input-placeholder" class="input-body" placeholder="单位名称" v-model="project_name"></u--input>
						</view>
					</view>
					<view class="actions">
						<view class="action" @click="handleResetForm()">
							<text>重</text>
							<text>置</text>
						</view>
						<view class="action search" @click="teamInfo()">
							<text>查</text>
							<text>询</text>
						</view>
					</view>
				</view>
				<view class="problem-wrapper" v-show="list.length < 1">
					<image src="https://www.mescroll.com/img/mescroll-empty.png"></image>
					<view class="">~ 空空如也 ~</view>
				</view>
				<view class="list" v-for="(item, index) in list" :key="index">
					<view class="wrapper">
						<view class="title">{{ item.dw_type }}:</view>
						<view class="text" v-for="(item2, index2) in item" :key="index2" v-if="item2.dw_name">
							{{ item2.dw_name }}
							<view class="labour " v-for="(item3, index3) in item2.team" :key="index3" >
								<view class="services" >{{ item3.type }}:</view>
								<view>
									<view class="name" v-for="(item4, index4) in item3" :key="index4" v-if="item4.dw_type">
										<view class="dw_name">
											{{ item4.dw_name }}
										</view>
										<view class="button">
											<view class="but" @click="approach(item4)" v-if="item4.state == 2 &&!nobutton">
												进场
											</view>
											<view class="butts" v-if="item4.state == 1 && !nobutton">
												进场
											</view>
											<view class="but buts" @click="exit(item4)" v-if="item4.state == 1&&!nobutton">
												退场
											</view>
											<view class="butts buts" v-if="item4.state == 2 && !nobutton">
												退场
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- </mescroll-uni> -->
	</view>
</template>

<script>
import { projectTeamTeamInfo, projectTeamUpdateTeamState } from '@/api/statistics.js'
import { mapGetters } from 'vuex'
export default {
	data() {
		return {
			nobutton:false,
			project_name: '',
			list: [],
			sbuject_id:'',
			id: '',
			state: ''
		}
	},
	computed: {
		...mapGetters({
			curProject: 'system/getCurProject'
		})
	},
	methods: {
		// 重置
		handleResetForm() {
		this.project_name='',
		this.teamInfo()
		},
		// 查询
		teamInfo() {
			if(this.sbuject_id){
				this.nobutton=true
				projectTeamTeamInfo({ project_id: this.sbuject_id,state:'1',company_name:this.project_name, }).then(res => {
					this.list = res.data.data
				})
			}else{
				this.nobutton=false
				projectTeamTeamInfo({ project_id:this.curProject.id,company_name:this.project_name,}).then(res => {
					this.list = res.data.data
				})
			}
			
		},
		// 进场
		approach(item) {
			this.id = item.id
			this.state = 1
			this.updateTeamState()
		},
		// 退场
		exit(item) {
			this.id = item.id
			this.state = 2
			this.updateTeamState()
		},
		// 进退场
		updateTeamState() {
			projectTeamUpdateTeamState({ id: this.id, state: this.state }).then(res => {
				if (res.data.code == 1) {
					uni.showToast({
						title: res.data.msg,
						icon: 'success',
						duration: 1000
					})
					this.teamInfo()
				}else{
					uni.showToast({
						title: res.data.msg,
						icon: 'error',
						duration: 1000
					})
				}
			})
		}
	},
	
	onLoad(e) {
		console.log(e.id);
		this.sbuject_id=e.id
		this.teamInfo()
	}
}
</script>

<style lang="scss" scoped>
.section-0 {
	z-index: 10;
	background-color: #2e5efe;
	.section-body {
		width: 100%;
		height: 100%;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;
		background-color: #fff;
		overflow: hidden;
		.form {
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
			.form-item {
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 25rpx;
				.label {
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					color: #1534ce;
				}
				.shape {
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}
				.input {
					float: left;
					width: calc(100% - 134rpx - 3rpx);
					.input-body {
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						padding: 0 !important;
						border: none;
						padding-left: 30rpx !important;
						padding-right: 30rpx !important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.7);
					}
					.input-placeholder {
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.5);
					}
				}
			}
			.actions {
				width: 100%;
				height: 50rpx;
				margin-top: 29rpx;
				padding-bottom: 40rpx;
				display: flex;
				justify-content: space-between;
				.action {
					width: 288rpx;
					height: 48rpx;
					background-color: #395cf5;
					border-radius: 20rpx;
					text-align: center;
					line-height: 48rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					color: #ffffff;
					text {
						&:first-child {
							margin-right: 20rpx;
						}
					}
				}
				.search {
					background-color: #1534ce;
				}
			}
		}
		.list {
			width: 670rpx;
			box-sizing: border-box;
			margin-left: 40rpx;
			padding-top: 38rpx;
			.wrapper {
				width: 100%;
				border-radius: 35rpx;
				background-size: cover;
				background-repeat: no-repeat;
				box-sizing: border-box;
				box-shadow: 0 0 20rpx 10rpx rgba(#bcbcb5, 0.17);
				padding: 28rpx 40rpx;
				margin-bottom: 24rpx;
				border: 1xp solid red;
				display: flex;
				.title {
					width: 140rpx;
					font-size: 30rpx;
					font-weight: bold;
				}
				.text {
					width: 450rpx;
					font-size: 30rpx;
					.labour {
						width: 570rpx;
						position: relative;
						left: -100rpx;
						display: flex;
						margin-top: 20rpx;
						.services {
							width: 140rpx;
							font-size: 30rpx;
						}
						.name {
							width: 430rpx;
							display: flex;
							margin-bottom: 20rpx;
							.dw_name {
								min-width: 250rpx;
							}
							.button {
								display: flex;
								.but {
									width: 80rpx;
									height: 40rpx;
									margin-top: 20rpx;
									text-align: center;
									color: white;
									line-height: 40rpx;
									font-size: 26rpx;
									background-color: #1534ce;
									border-radius: 20rpx;
								}
								.buts {
									margin-left: 20rpx;
								}
								.butts {
									width: 80rpx;
									height: 40rpx;
									margin-top: 20rpx;
									text-align: center;
									color: white;
									line-height: 40rpx;
									font-size: 26rpx;
									background-color: #cccccc;
									border-radius: 20rpx;
								}
							}
						}
					}
				}
			}
		}
		.problem-wrapper {
			color: #808080;
			margin: 0 auto;
			text-align: center;
			image {
				margin-top: 300rpx;
				width: 200rpx;
				height: 200rpx;
			}
		}
	}
}
</style>
